import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:xiongan_app_yy/common/user_singleton.dart';
import 'package:xiongan_app_yy/provider/warehouse_info.dart';
import 'package:xiongan_app_yy/widgets/comm/left_icon_widget.dart';
import 'package:xiongan_app_yy/widgets/comm/text_card_widget.dart';

class WarehouseSelectionPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return WarehouseSelectionPageState();
  }
}

class WarehouseSelectionPageState extends State<WarehouseSelectionPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: new AppBar(
        leading: LeftIconWidget(icon: Icons.chevron_left, isize: 36),
        backgroundColor: Color(0XFF00A5F1),
        title: Text(
          "仓库选择",
          style: TextStyle(fontSize: 18),
        ),
        elevation: 0,
        centerTitle: true,
      ),
      body: ListView.separated(
          itemBuilder: (BuildContext context, int index) {
            return TextCardWidget(
                title: DataSingleton().warehouse.elementAt(index).text,
                onPressed: () {
                  DataSingleton().warehouseChoice =
                      DataSingleton().warehouse.elementAt(index);
                  Provider.of<WarehouseInfo>(context)
                      .setMode(DataSingleton().warehouseChoice);
                  print(DataSingleton().warehouseChoice.id);
                  Navigator.pop(context);
                },
                visibility: true,
                border: Border.fromBorderSide(BorderSide.none));
          },
          separatorBuilder: (BuildContext context, int index) =>
              Divider(height: 1, color: Color(0xffdddddd)),
          itemCount: DataSingleton().warehouse.length),
    );
  }
}
